#pragma once

#include <iostream>
#include "opencv2/opencv.hpp"

static cv::Mat erode_kernel =
    cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5, 5));
static constexpr double rect_value_thresh = 4;

enum class DART_STATUS
{
    DART_STATUS_NOT_READY,
    DART_STATUS_READY
};

bool canChangeStatus(cv::Mat &image)
{
    cv::Scalar green_low = cv::Scalar(50, 100, 115);
    cv::Scalar green_high = cv::Scalar(90, 255, 255);

    cv::cvtColor(image, image, cv::COLOR_BGR2HSV);

    cv::Mat mask;
    cv::inRange(image, green_low, green_high, mask);
    cv::erode(mask, mask, erode_kernel);

    std::vector<std::vector<cv::Point>> contours;

    cv::findContours(mask, contours, cv::RETR_EXTERNAL,
                     cv::CHAIN_APPROX_SIMPLE);

    for (const std::vector<cv::Point> contour : contours)
    {
        cv::Rect rect = cv::boundingRect(contour);
        double value = rect.width / rect.height;
        if (value >= rect_value_thresh)
        {
            std::cout << "[WMJDart] Received ready signal, ready to launch"
                      << std::endl;
            return true;
        }
    }
    return false;
}
